%user define
Re=150;
D=0.0016;
nu=1e-6;
U=Re*nu/D;
dt=0.0001;
sampleTime=2;
wantedIte=sampleTime/dt;
Ur=[3;4;5;6;7;8;9;10];
results=zeros(size(Ur,1),4);
results(:,1)=Ur;
subdir=dir(fullfile(pwd,'viv*'));
for i=1:length(subdir)
    %get forceCoeff
    timePath=fullfile(pwd,subdir(i).name,'postProcessing','forceCoeffs');
    timedir=dir(timePath);
    timewanted = '0';%arbitary number
    for j=1:length(timedir) %get the latest time folder
        if( isequal(timedir(j).name, '.')  ...
            || isequal(timedir(j).name,'..') ...
            || ~timedir(j).isdir)
            continue;
        end
        timewanted=num2str(max(str2double(timewanted),str2double(timedir(j).name)));
    end
    forceCoeffPath=fullfile(timePath,timewanted,'*.dat');
    forceCoeffdir=dir(forceCoeffPath);
    str=fullfile(timePath,timewanted,forceCoeffdir(1).name);
    KK=1;
    if(isequal(length(forceCoeffdir),1))
        forceCoeff_cell{1,i}=importdata(str);
    else
        for k=1:length(forceCoeffdir)
            if(forceCoeffdir(k).bytes>forceCoeffdir(KK).bytes)
                str=fullfile(timePath,timewanted,forceCoeffdir(k).name);
                KK=k;
            end
        end
        forceCoeff_cell{1,i}=importdata(str);
    end
    
    totalLength=size(forceCoeff_cell{1,i}.data,1);
    overIter=(totalLength<=wantedIte);
    if(overIter)
        t=forceCoeff_cell{1,i}.data(:,1);
        Cd=forceCoeff_cell{1,i}.data(:,2);
        Cl=forceCoeff_cell{1,i}.data(:,4);
    else
        t=forceCoeff_cell{1,i}.data(totalLength-wantedIte:totalLength,1);
        Cd=forceCoeff_cell{1,i}.data(totalLength-wantedIte:totalLength,2);
        Cl=forceCoeff_cell{1,i}.data(totalLength-wantedIte:totalLength,4);
    end
    results(i,2)=mean(Cd);
    results(i,3)=rms(Cl);
    
    %get vibration amplitude
    moveDatPath=fullfile(pwd,subdir(i).name,'plotfile.dat');
    moveDat=importdata(moveDatPath);
    if(overIter)
        y=moveDat(:,3);
    else
        y=moveDat(totalLength-wantedIte:totalLength,3);
    end
    
    results(i,4)=max(y)/D;
end
        